package com.csx.saas.platform.tenant.enumeration;

import com.csx.basic.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 企业
 * </p>
 *
 * @author ChenSongXin
 * @date 2021-02-28
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "TenantStateEnum", description = "状态\n#{NORMAL:正常;LOCKED:锁定;EXPIRE:到期-枚举")
public enum TenantStateEnum implements BaseEnum {

    /**
     * NORMAL="正常"
     */
    NORMAL("正常"),
    /**
     * LOCKED="锁定"
     */
    LOCKED("锁定"),
    /**
     * EXPIRE="到期"
     */
    EXPIRE("到期"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static TenantStateEnum match(String val, TenantStateEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static TenantStateEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(TenantStateEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "NORMAL,LOCKED,EXPIRE", example = "NORMAL")
    public String getCode() {
        return this.name();
    }

}
